#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
#include<unordered_map>
using namespace std;

class Solution {
public:
    int findKthLargest(vector<int>& nums, int k) {
        srand(time(0));
        return sort(0, nums.size() - 1, nums, k);
    }

    int sort(int l, int r, vector<int>& nums, int k)
    {
        if (l == r) return nums[l];
        int left = l - 1, right = r + 1;
        int key = nums[getRandom(l, r)];
        int i = l;
        while (i < right)
        {
            if (nums[i] < key) swap(nums[++left], nums[i++]);
            else if (nums[i] == key) i++;
            else swap(nums[--right], nums[i]);
        }
        int c = r - right + 1, b = right - left - 1;
        if (c >= k) return sort(right, r, nums, k);
        else if (b + c >= k) return key;
        else return sort(l, left, nums, k - b - c);
    }

    int getRandom(int left, int right)
    {
        return (rand() % (right - left + 1)) + left;
    }
};

int main() {
    return 0;
}